package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.AnalysisManageOperateLog;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.AnalysisManageOperateLogDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2018-11-26 15:05:33
 */
public class AnalysisManageOperateLogConverts {

    private static Logger LOG = LoggerFactory.getLogger(AnalysisManageOperateLogConverts.class);

    public static List<AnalysisManageOperateLogDTO> convert(List<AnalysisManageOperateLog> analysisManageOperateLogList) {
        if (CollectionUtils.isEmpty(analysisManageOperateLogList)) {
            return Collections.EMPTY_LIST;
        }

        List<AnalysisManageOperateLogDTO> analysisManageOperateLogListResult = Lists.newArrayList();
        for (AnalysisManageOperateLog analysisManageOperateLog : analysisManageOperateLogList) {
            analysisManageOperateLogListResult.add(convert(analysisManageOperateLog));
        }
        return analysisManageOperateLogListResult;
    }

    public static AnalysisManageOperateLogDTO convert(AnalysisManageOperateLog analysisManageOperateLog) {
        try {
            return BeanUtils.copy(analysisManageOperateLog, AnalysisManageOperateLogDTO.class);
        } catch (Exception e) {
            LOG.error("AnalysisManageOperateLog到AnalysisManageOperateLogDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "AnalysisManageOperateLog到AnalysisManageOperateLogDTO转换失败", e);
        }
    }

    public static AnalysisManageOperateLog convert(AnalysisManageOperateLogDTO analysisManageOperateLogDTO) {
        try {
            return BeanUtils.copy(analysisManageOperateLogDTO, AnalysisManageOperateLog.class);
        } catch (Exception e) {
            LOG.error("AnalysisManageOperateLogDTO到AnalysisManageOperateLog转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "AnalysisManageOperateLogDTO到AnalysisManageOperateLog转换失败", e);
        }
    }
}